// StatCalculator is a class that analyzes a MidSong object and counts notes and intervals used in the song, 
// theyr frequence and distribution through the song. Reads basic song data e.g. how many instruments are used 
import java.util.Arrays;

class StatCalculator {
  MidSong song;
  ArrayList<TrackStats> tracks;

  StatCalculator(MidSong song) {
    this.song = song;
    tracks = new ArrayList<TrackStats>();
  }
  
  void claculateSongStatistics() {
    for (int i = 0; i < song.tracks.size(); i++) {
      MIDITrack currentTrack = song.tracks.get(i);
      tracks.add(new TrackStats(currentTrack.instrumentNumber));
      for (int j = 0; j < currentTrack.closedNotes.size(); j++) {
        MIDINote note = currentTrack.closedNotes.get(j);
        tracks.get(lastTrack()).addParameter(note.key, tracks.get(lastTrack()).notes);
        tracks.get(lastTrack()).addParameter(note.velocity, tracks.get(lastTrack()).velocityes);
        tracks.get(lastTrack()).addParameter(note.duration, tracks.get(lastTrack()).durations);
      }
    }
    println("Calculator read " + tracks.size());
  }

  int lastTrack() {
    return tracks.size()-1;
  }
}

